package com.lkd.controller;

import com.lkd.dto.RegionAllPageDto;
import com.lkd.dto.RegionPageDto;
import com.lkd.entity.Node;
import com.lkd.result.PageBean;
import com.lkd.result.Result;
import com.lkd.service.NodeService;
import com.lkd.vo.NodeVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/vm-service/node")
@Slf4j

public class NodeController {
    //使用Autowired注解，自动注入NodeService
    @Autowired
    private NodeService nodeService;

    //根据区域id查询该区域下的点位列表
    @GetMapping("/search")
    public Result listByRid(RegionAllPageDto regionAllPageDto){
        PageBean pageBean = nodeService.listByRid(regionAllPageDto);
        return Result.success(pageBean);
    }

    @PostMapping
    //新增点位
    public Result save(Node node){
        Boolean result=nodeService.save(node);
        return Result.success(result);
    }

    @GetMapping("/vmList/{nodeId}")
    //根据点位id查询该点位下的设备列表
    public Result getVmList(@PathVariable("nodeId") Long nodeId){
        List<NodeVo> list= nodeService.getVmList(nodeId);
        return Result.success(list);
    }

    @PutMapping
    //修改点位
    public Result update(@RequestBody Node node){
        Boolean result=nodeService.update(node);
        return Result.success(result);
    }

    //删除点位
    @DeleteMapping("{nodeId}")
    public Result delete(@PathVariable("nodeId") Long nodeId){
        Boolean result = nodeService.deleteById(nodeId);
        return Result.success(result);
    }

    //点位数量
    @GetMapping("/count")
    public Result count(){
        Integer count =  nodeService.count();
        return Result.success(count);
    }
}
